package dynamicrange;

import javax.swing.JPanel;
import java.awt.Frame;
import java.awt.BorderLayout;
import java.awt.Point;

import javax.swing.JDialog;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.awt.Dimension;
import javax.swing.JButton;

public class DynamicRangeAmpDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JLabel jLabel = null;
	private JTextField jTextFieldCenter = null;
	private JLabel jLabel1 = null;
	private JTextField jTextFieldSpan = null;
	private JButton jButtonCancel = null;
	private JButton jButtonOK = null;
	public  boolean OK = false;
	public  double Span  = 0.0;
	public  double Center = 0.0;
	
	public void updateData(boolean set){
		if(set){
			jTextFieldCenter.setText(String.format("%f",Center));
			jTextFieldSpan.setText(String.format("%f",Span));
		}
		else{
			Center = Double.valueOf(jTextFieldCenter.getText());
			Span   = Double.valueOf(jTextFieldSpan.getText());
		}
	}
	/**
	 * @param owner
	 */
	public DynamicRangeAmpDialog(Frame owner) {
		super(owner,true);
		initialize();
		setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE );
		if(owner!=null){
			Point p = owner.getLocationOnScreen();
			Dimension d = owner.getSize();
			Dimension dm = this.getSize();
			p.x += (d.width-dm.width)/2;
			p.y += (d.height-dm.height)/2;
			setLocation(p);
		}
	}
	public void setDialogLocationCenter(JPanel owner){
		Point p = owner.getLocationOnScreen();
		Dimension d = owner.getSize();
		Dimension dm = this.getSize();
		p.x += (d.width-dm.width)/2;
		p.y += (d.height-dm.height)/2;
		setLocation(p);
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(213, 159);
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(12, 46, 56, 24));
			jLabel1.setText("Span");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(11, 17, 56, 23));
			jLabel.setText("Center");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJTextFieldCenter(), null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(getJTextFieldSpan(), null);
			jContentPane.add(getJButtonCancel(), null);
			jContentPane.add(getJButtonOK(), null);
			getRootPane().setDefaultButton(getJButtonOK());
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTextFieldCenter	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCenter() {
		if (jTextFieldCenter == null) {
			jTextFieldCenter = new JTextField();
			jTextFieldCenter.setBounds(new Rectangle(71, 16, 109, 25));
		}
		return jTextFieldCenter;
	}

	/**
	 * This method initializes jTextFieldSpan	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldSpan() {
		if (jTextFieldSpan == null) {
			jTextFieldSpan = new JTextField();
			jTextFieldSpan.setBounds(new Rectangle(73, 46, 108, 24));
		}
		return jTextFieldSpan;
	}

	/**
	 * This method initializes jButtonCancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setBounds(new Rectangle(6, 86, 89, 31));
			jButtonCancel.setText("Cancel");
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					OK = false;
					setVisible(false);
				}
			});
		}
		return jButtonCancel;
	}

	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new Rectangle(106, 85, 83, 31));
			jButtonOK.setText("OK");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					updateData(false);
					OK = true;
					setVisible(false);
				}
			});
		}
		return jButtonOK;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
